package com.th.apicenter.wifi;

import com.th.apicenter.wifi.entity.ThWifiData;
import com.th.apicenter.wifi.service.ThWifiDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author kay
 * @date 2025/6/23
 * @TODO
 */
@RestController
@RequestMapping("/wifi")
@Slf4j
public class WifiController {

    @Autowired
    private ThWifiDataService thWifiDataService;

    /**
     * https://apibiz.tinghongzz.com/wifi/receive?aid=__AID__&cid=__CID__&sid=__SID__&os=__OS__&idfa=__IDFA__&imei=__IMEI__&oaid=__OAID__&caid=__CAID__&caid_version=__CAID_VERSION__&last_caid=__LAST_CAID__&last_caid_version=__LAST_CAID_VERSION__&stime=__STIME__
     * &mac=__MAC__&ip=__IP__&callback_url=__CALLBACK_URL__
     */
    @GetMapping("/receive")
    public void receiveUrl(@RequestParam(name = "account_id", required = false) String account_id,
                           @RequestParam(name = "aid", required = false) String aid,
                           @RequestParam(name = "cid", required = false) String cid,
                           @RequestParam(name = "sid", required = false) String sid,
                           @RequestParam(name = "os", required = false) String os,
                           @RequestParam(name = "idfa", required = false) String idfa,
                           @RequestParam(name = "imei", required = false) String imei,
                           @RequestParam(name = "oaid", required = false) String oaid,
                           @RequestParam(name = "caid", required = false) String caid,
                           @RequestParam(name = "caid_version", required = false) String caid_version,
                           @RequestParam(name = "last_caid", required = false) String last_caid,
                           @RequestParam(name = "last_caid_version", required = false) String last_caid_version,
                           @RequestParam(name = "stime", required = false) String stime,
                           @RequestParam(name = "mac", required = false) String mac,
                           @RequestParam(name = "ip", required = false) String ip,
                           @RequestParam(name = "callback_url", required = false) String callback_url) {
        log.info("wifi数据-------------------------------------------------------------------------");
        log.info("account_id:{}", account_id);
        log.info("aid:{}", aid);
        log.info("cid:{}", cid);
        log.info("sid:{}", sid);
        log.info("os:{}", os);
        log.info("idfa:{}", idfa);
        log.info("imei:{}", imei);
        log.info("oaid:{}", oaid);
        log.info("caid:{}", caid);
        log.info("caid_version:{}", caid_version);
        log.info("last_caid:{}", last_caid);
        log.info("last_caid_version:{}", last_caid_version);
        log.info("stime:{}", stime);
        log.info("mac:{}", mac);
        log.info("ip:{}", ip);
        log.info("callback_url:{}", callback_url);
        ThWifiData thWifiData = new ThWifiData();
        thWifiData.setAccountId(aid);
        thWifiData.setAid(aid);
        thWifiData.setCid(cid);
        thWifiData.setSid(sid);
        thWifiData.setOs(os);
        thWifiData.setIdfa(idfa);
        thWifiData.setImei(imei);
        thWifiData.setOaid(oaid);
        thWifiData.setCaid(caid);
        thWifiData.setCaidVersion(caid_version);
        thWifiData.setLastCaid(last_caid);
        thWifiData.setLastCaidVersion(last_caid_version);
        thWifiData.setStime(stime);
        thWifiData.setMac(mac);
        thWifiData.setIp(ip);
        thWifiData.setCallbackUrl(callback_url);
        thWifiData.setCreateDate(new Date());
        thWifiDataService.receive(thWifiData);
    }
}
